package cn.wolfcode.trip.base.domain;

import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Setter
@Getter
@ToString
@JsonIgnoreProperties("handler")
public class Travel extends BaseDomain {

    public static final Integer STATE_REFUSE = -1; //拒绝
    public static final Integer STATE_TEMP = 0; //草稿
    public static final Integer STATE_WAIT = 1; //待审核
    public static final Integer STATE_RELEASE = 2; //审核通过

    private String title;//标题
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date travelTime;//出游时间

    private String perExpends;//人均消费

    private Integer days;//出游天数

    private Integer person;//同行者身份
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd HH-mm-ss", timezone = "GMT+8")
    private Date createTime;//创建时间

    @JsonFormat(pattern = "yyyy-MM-dd HH-mm", timezone = "GMT+8")
    private Date releaseTime;//发布时间

    private Boolean isPublic;//是否公开

    private String coverUrl;//封面图片

    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date lastUpdateTime;//最后更新时间

    private Region place;//游玩地点

    private User author;//作者

    private Integer state = STATE_TEMP;//状态

    private TravelContent content;//游记文本

    private Long viewCount;//浏览量

    private Long likeCount;//点赞量

    public String getStateName() {
        String stateName = "";
        if (state == Travel.STATE_TEMP) {
            stateName = "草稿";
        } else if (state == Travel.STATE_WAIT) {
            stateName = "待审核";
        } else if (state == Travel.STATE_REFUSE) {
            stateName = "已拒绝";
        } else if (state == Travel.STATE_RELEASE) {
            stateName = "审核通过";
        }
        return stateName;
    }

    public String getPersonName() {
        String str = "";
        if (person != null) {
            switch (person) {
                case 1:
                    str = "一个人的旅行";
                    break;
                case 2:
                    str = "和父母";
                    break;
                case 3:
                    str = "和朋友";
                    break;
                case 4:
                    str = "和同事";
                    break;
                case 5:
                    str = "和爱人";
                    break;
                default:
                    str = "和驴友";
            }
        }
        return str;
    }

    public Object getJson() {
        Map<String, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("title", title);
        if (coverUrl != null) {
            map.put("coverUrl", coverUrl);
        }
        return JSON.toJSONString(map);
    }


}